#include <stdio.h>

int binary_search(int array[], int item, int length);

int main(int argc, char const *argv[]){
    int my_array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int my_array_length = sizeof(my_array)/sizeof(my_array[0]);

    printf("%d\n", binary_search(my_array, 5, my_array_length));
    printf("%d\n", binary_search(my_array, 15, my_array_length));
    return 0;
}

int binary_search(int array[], int item, int length){
    int low = 0, high = length-1;
    while(low <= high){
        int mid = (low + high)/2;
        int guess = array[mid];
        if(guess == item)
            return mid;
        else if(guess > item)
            low = mid + 1;
        else if(guess < item)
            high = mid - 1;
    }
    return -1;
}
